/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui.gui.table.model;

import javax.swing.table.AbstractTableModel;
import model.Sale;
import model.SaleLineItem;

/**
 *
 * @author Mads Nielsen
 */
public class SaleTableModel extends AbstractTableModel {

    private String[] colNames = {"Vare", "Antal", "Stk. pris", "Pris"};
    private Class[] colTypes = {java.lang.String.class, java.lang.Integer.class,
        java.lang.Double.class, java.lang.Double.class
    };
    private Sale sale;

    public SaleTableModel(Sale sale) {
        super();
        this.sale = sale;
    }

    @Override
    public int getRowCount() {
        return sale.getLineItems().length;
    }

    @Override
    public int getColumnCount() {
        return colNames.length;
    }

    @Override
    public String getColumnName(int index) {
        return colNames[index];
    }

    @Override
    public Class getColumnClass(int index) {
        return colTypes[index];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        SaleLineItem line = sale.getLineItems()[rowIndex];

        switch (columnIndex) {
            case 0:
                return line.getItem().getName();
            case 1:
                return line.getQty();
            case 2:
                return line.getItem().getTotalPrice();
            case 3:
                return (Double) line.getTotal();
            default:
                return null;
        }
    }
}
